package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.attendrule.*;
import org.jsola.hr.dto.attendschedule.AttendPeriodDTO;
import org.jsola.hr.dto.attendschedule.AttendScheduleSaveDTO;
import org.jsola.hr.service.IAttendRuleService;
import org.jsola.hr.service.IAttendScheduleService;
import org.jsola.hr.vo.*;
import org.jsola.module.ModuleContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.TestCommonConstans.*;

@Component
public class AttendRuleTestHelper extends BaseTestHelper {

    @Autowired
    private IAttendRuleService attendRuleService;
    @Autowired
    private EmpDepTestHelper empDepTestHelper;
    @Autowired
    private AttendPeriodTestHelper attendPeriodTestHelper;
    @Autowired
    private AttendScheduleTestHelper attendScheduleTestHelper;
    @Autowired
    private IAttendScheduleService attendScheduleService;

    /**
     * 自由上下班
     * @return
     */
    public AttendRuleAddDTO getFreeAttendRule() {

        // 加载部门、人员
        ModuleContext moduleContext = new ModuleContext();
        empDepTestHelper.batchSaveEmpDepExample(moduleContext);

        List<DepInfoVO> depList = moduleContext.get(CODE_DEP_LIST);
        CompanyVO companyVO = moduleContext.get(CODE_COMPANY);
        List<EmpInfoVO> empInfoList = moduleContext.get(CODE_EMP_LIST);


        AttendRuleAddDTO attendRuleAddDTO = new AttendRuleAddDTO();

        // 方案名称
        String planName = getRandomValue("varchar",100);
        // 方案类型 ; 1-固定时间上下班,2-按班次上下班,3-自由上下班
        int planType = 3;

        attendRuleAddDTO.setCompanyId(companyVO.getId());
        // 打卡部门
        List<AttendRuleDeptAddDTO> deptList = this.getDeptList(depList);
        // 打卡人员
        List<AttendRuleStaffAddDTO> staffList = this.getStaffList(empInfoList, depList);
        // 白名单
        List<AttendRuleWhitelistAddDTO> whitelist = this.getWhitelist(empInfoList, depList);
        // 汇报对象
        List<AttendRuleReportAddDTO> reportList = this.getReportList(empInfoList, depList);
        // 打卡地点-位置
        List<AttendRuleLocationAddDTO> locationList = this.getLocationList();
        // 打卡地点-wifi
        List<AttendRuleWifiAddDTO> wifiList = this.getWifiList();
        // 打卡时间
        List<AttendRulePunchTimeAddDTO> punchTimeList = this.getPunchTimeListRandomFree();
        // 特殊日期-必须打卡的日期
        List<NeedPunchDateAddDTO> needPunchDateList = null; //this.getNeedPunchDateList();
        // 特殊日期-不必打卡的日期
        List<NoNeedPunchDateAddDTO> noNeedPunchDateList = this.getNoNeedPunchDateList();
        // 加班规则 1-以加班申请为准,2-以打卡时间为准,3-以加班申请核算打卡记录
        int overtimeRule = SafeKit.getInteger(getRandomValue("int",0));
        // 是否同步中国节假日不能为空
        int isSynchLegalHoliday = SafeKit.getInteger(getRandomValue("tinyint",0));
        // 是否手机提醒;1-是,0-否
        int isRemind = SafeKit.getInteger(getRandomValue("tinyint",0));
        // 上班前x分钟
        int remindBefore = SafeKit.getInteger(getRandomValue("int",0));
        // 下班后x分钟
        int remindAfter = SafeKit.getInteger(getRandomValue("int",0));
        // 员工打卡时必须拍照
        int isTakePhoto = SafeKit.getInteger(getRandomValue("tinyint",0));
        // 只能拍照
        int isOnlyPhoto = SafeKit.getInteger(getRandomValue("tinyint",0));
        // 范围外打卡
        int punchRange = SafeKit.getInteger(getRandomValue("int",0));
        // 是否补卡申请
        int isMakeUp = SafeKit.getInteger(getRandomValue("tinyint",0));
        // 每月不高于x下次
        int maxMakeUpCounts = SafeKit.getInteger(getRandomValue("int",0));
        // 生效时间
        int takeEffect = SafeKit.getInteger(getRandomValue("int",0));

        // 方案名称
        attendRuleAddDTO.setPlanName(planName);
        // 规则类型不能为空 (1-固定时间上下班,2-按班次上下班,3-自由上下班)
        attendRuleAddDTO.setPlanType(planType);
        // 打卡部门
        attendRuleAddDTO.setDeptList(deptList);
        // 打卡人员
        attendRuleAddDTO.setStaffList(staffList);
        // 白名单
        attendRuleAddDTO.setWhitelist(whitelist);
        // 汇报对象
        attendRuleAddDTO.setReportList(reportList);
        // 打卡地点-位置
        attendRuleAddDTO.setLocationList(locationList);
        // 打卡地点-wifi
        attendRuleAddDTO.setWifiList(wifiList);
        // 打卡时间
        attendRuleAddDTO.setPunchTimeList(punchTimeList);
        // 特殊日期-必须打卡的日期
        attendRuleAddDTO.setNeedPunchDateList(needPunchDateList);
        // 特殊日期-不必打卡的日期
        attendRuleAddDTO.setNoNeedPunchDateList(noNeedPunchDateList);
        // 加班规则不能为空
        attendRuleAddDTO.setOvertimeRule(overtimeRule);
        // 是否同步中国节假日不能为空
//        attendRuleAddDTO.setIsSynchLegalHoliday(isSynchLegalHoliday);
//        // 是否手机提醒
//        attendRuleAddDTO.setIsRemind(isRemind);
//        // 上班前x分钟
//        attendRuleAddDTO.setRemindBefore(remindBefore);
//        // 下班后x分钟
//        attendRuleAddDTO.setRemindAfter(remindAfter);
//        // 员工打卡时必须拍照不能为空
//        attendRuleAddDTO.setIsTakePhoto(isTakePhoto);
//        // 只能拍照
//        attendRuleAddDTO.setIsOnlyPhoto(isOnlyPhoto);
//        // 范围外打卡
//        attendRuleAddDTO.setPunchRange(punchRange);
//        // 是否补卡申请
//        attendRuleAddDTO.setIsMakeUp(isMakeUp);
        // 每月不高于x下次
        attendRuleAddDTO.setMaxMakeUpCounts(maxMakeUpCounts);
        // 生效时间
        attendRuleAddDTO.setTakeEffect(takeEffect);

        return attendRuleAddDTO;
    }

    /**
     * 按班次上下班
     *
     * @return
     */
    public AttendRuleAddDTO getScheduleAttendRule() {

        // 加载部门、人员
        ModuleContext moduleContext = new ModuleContext();
        empDepTestHelper.batchSaveEmpDepExample(moduleContext);

        List<DepInfoVO> depList = moduleContext.get(CODE_DEP_LIST);
        CompanyVO companyVO = moduleContext.get(CODE_COMPANY);
        List<EmpInfoVO> empInfoList = moduleContext.get(CODE_EMP_LIST);

        // 排班
        AttendScheduleSaveDTO attendScheduleSaveDTO = attendScheduleTestHelper.getAttendScheduleSaveDTO();

        String tmpAttendShiftId = attendScheduleService.save(attendScheduleSaveDTO, buildTokenUser());

        AttendRuleAddDTO attendRuleAddDTO = new AttendRuleAddDTO();
        attendRuleAddDTO.setTmpAttendShiftId(tmpAttendShiftId);

        // 方案名称
        String planName = getRandomValue("varchar",100);
        // 方案类型 ; 1-固定时间上下班,2-按班次上下班,3-自由上下班
        int planType = 2;

        attendRuleAddDTO.setCompanyId(companyVO.getId());
        // 打卡部门
        List<AttendRuleDeptAddDTO> deptList = this.getDeptList(depList);
        // 打卡人员
        List<AttendRuleStaffAddDTO> staffList = this.getStaffList(empInfoList, depList);
        // 白名单
        List<AttendRuleWhitelistAddDTO> whitelist = this.getWhitelist(empInfoList, depList);
        // 汇报对象
        List<AttendRuleReportAddDTO> reportList = this.getReportList(empInfoList, depList);
        // 打卡地点-位置
        List<AttendRuleLocationAddDTO> locationList = this.getLocationList();
        // 打卡地点-wifi
        List<AttendRuleWifiAddDTO> wifiList = this.getWifiList();
        // 打卡时间
        List<AttendRulePunchTimeAddDTO> punchTimeList = null; // this.getPunchTimeListRandom();
        // 特殊日期-必须打卡的日期
        List<NeedPunchDateAddDTO> needPunchDateList = null; //this.getNeedPunchDateList();
        // 特殊日期-不必打卡的日期
        List<NoNeedPunchDateAddDTO> noNeedPunchDateList = this.getNoNeedPunchDateList();
        // 加班规则 1-以加班申请为准,2-以打卡时间为准,3-以加班申请核算打卡记录
        int overtimeRule = SafeKit.getInteger(getRandomValue("int",0));
        // 是否同步中国节假日不能为空
        int isSynchLegalHoliday = SafeKit.getInteger(getRandomValue("tinyint",0));
        // 是否手机提醒;1-是,0-否
        int isRemind = SafeKit.getInteger(getRandomValue("tinyint",0));
        // 上班前x分钟
        int remindBefore = SafeKit.getInteger(getRandomValue("int",0));
        // 下班后x分钟
        int remindAfter = SafeKit.getInteger(getRandomValue("int",0));
        // 员工打卡时必须拍照
        int isTakePhoto = SafeKit.getInteger(getRandomValue("tinyint",0));
        // 只能拍照
        int isOnlyPhoto = SafeKit.getInteger(getRandomValue("tinyint",0));
        // 范围外打卡
        int punchRange = SafeKit.getInteger(getRandomValue("int",0));
        // 是否补卡申请
        int isMakeUp = SafeKit.getInteger(getRandomValue("tinyint",0));
        // 每月不高于x下次
        int maxMakeUpCounts = SafeKit.getInteger(getRandomValue("int",0));
        // 生效时间
        int takeEffect = SafeKit.getInteger(getRandomValue("int",0));

        // 方案名称
        attendRuleAddDTO.setPlanName(planName);
        // 规则类型不能为空 (1-固定时间上下班,2-按班次上下班,3-自由上下班)
        attendRuleAddDTO.setPlanType(planType);
        // 打卡部门
        attendRuleAddDTO.setDeptList(deptList);
        // 打卡人员
        attendRuleAddDTO.setStaffList(staffList);
        // 白名单
        attendRuleAddDTO.setWhitelist(whitelist);
        // 汇报对象
        attendRuleAddDTO.setReportList(reportList);
        // 打卡地点-位置
        attendRuleAddDTO.setLocationList(locationList);
        // 打卡地点-wifi
        attendRuleAddDTO.setWifiList(wifiList);
        // 打卡时间
        attendRuleAddDTO.setPunchTimeList(punchTimeList);
        // 特殊日期-必须打卡的日期
        attendRuleAddDTO.setNeedPunchDateList(needPunchDateList);
        // 特殊日期-不必打卡的日期
        attendRuleAddDTO.setNoNeedPunchDateList(noNeedPunchDateList);
        // 加班规则不能为空
        attendRuleAddDTO.setOvertimeRule(overtimeRule);
        // 是否同步中国节假日不能为空
//        attendRuleAddDTO.setIsSynchLegalHoliday(isSynchLegalHoliday);
//        // 是否手机提醒
//        attendRuleAddDTO.setIsRemind(isRemind);
//        // 上班前x分钟
//        attendRuleAddDTO.setRemindBefore(remindBefore);
//        // 下班后x分钟
//        attendRuleAddDTO.setRemindAfter(remindAfter);
//        // 员工打卡时必须拍照不能为空
//        attendRuleAddDTO.setIsTakePhoto(isTakePhoto);
//        // 只能拍照
//        attendRuleAddDTO.setIsOnlyPhoto(isOnlyPhoto);
//        // 范围外打卡
//        attendRuleAddDTO.setPunchRange(punchRange);
//        // 是否补卡申请
//        attendRuleAddDTO.setIsMakeUp(isMakeUp);
        // 每月不高于x下次
        attendRuleAddDTO.setMaxMakeUpCounts(maxMakeUpCounts);
        // 生效时间
        attendRuleAddDTO.setTakeEffect(takeEffect);

        return attendRuleAddDTO;

    }

    public AttendRuleAddDTO getFixedAttendRuleAddDTO() {

        // 加载部门、人员
        ModuleContext moduleContext = new ModuleContext();
        empDepTestHelper.batchSaveEmpDepExample(moduleContext);

        List<DepInfoVO> depList = moduleContext.get(CODE_DEP_LIST);
        CompanyVO companyVO = moduleContext.get(CODE_COMPANY);
        List<EmpInfoVO> empInfoList = moduleContext.get(CODE_EMP_LIST);

        AttendRuleAddDTO attendRuleAddDTO = new AttendRuleAddDTO();

        // 方案名称
        String planName = getRandomValue("varchar",100);
        // 方案类型 ; 1-固定时间上下班,2-按班次上下班,3-自由上下班
        int planType = 1;

        attendRuleAddDTO.setCompanyId(companyVO.getId());
        // 打卡部门
        List<AttendRuleDeptAddDTO> deptList = this.getDeptList(depList);
        // 打卡人员
        List<AttendRuleStaffAddDTO> staffList = this.getStaffList(empInfoList, depList);
        // 白名单
        List<AttendRuleWhitelistAddDTO> whitelist = this.getWhitelist(empInfoList, depList);
        // 汇报对象
        List<AttendRuleReportAddDTO> reportList = this.getReportList(empInfoList, depList);
        // 打卡地点-位置
        List<AttendRuleLocationAddDTO> locationList = this.getLocationList();
        // 打卡地点-wifi
        List<AttendRuleWifiAddDTO> wifiList = this.getWifiList();
        // 打卡时间
        List<AttendRulePunchTimeAddDTO> punchTimeList = this.getPunchTimeListRandom();
        // 特殊日期-必须打卡的日期
        List<NeedPunchDateAddDTO> needPunchDateList = this.getNeedPunchDateList();
        // 特殊日期-不必打卡的日期
        List<NoNeedPunchDateAddDTO> noNeedPunchDateList = this.getNoNeedPunchDateList();
        // 加班规则 1-以加班申请为准,2-以打卡时间为准,3-以加班申请核算打卡记录
        int overtimeRule = SafeKit.getInteger(getRandomValue("int",0));
        // 是否同步中国节假日不能为空
        int isSynchLegalHoliday = SafeKit.getInteger(getRandomValue("tinyint",0));
        // 是否手机提醒;1-是,0-否
        int isRemind = SafeKit.getInteger(getRandomValue("tinyint",0));
        // 上班前x分钟
        int remindBefore = SafeKit.getInteger(getRandomValue("int",0));
        // 下班后x分钟
        int remindAfter = SafeKit.getInteger(getRandomValue("int",0));
        // 员工打卡时必须拍照
        int isTakePhoto = SafeKit.getInteger(getRandomValue("tinyint",0));
        // 只能拍照
        int isOnlyPhoto = SafeKit.getInteger(getRandomValue("tinyint",0));
        // 范围外打卡
        int punchRange = SafeKit.getInteger(getRandomValue("int",0));
        // 是否补卡申请
        int isMakeUp = SafeKit.getInteger(getRandomValue("tinyint",0));
        // 每月不高于x下次
        int maxMakeUpCounts = SafeKit.getInteger(getRandomValue("int",0));
        // 生效时间
        int takeEffect = SafeKit.getInteger(getRandomValue("int",0));

        // 方案名称
        attendRuleAddDTO.setPlanName(planName);
        // 规则类型不能为空 (1-固定时间上下班,2-按班次上下班,3-自由上下班)
        attendRuleAddDTO.setPlanType(planType);
        // 打卡部门
        attendRuleAddDTO.setDeptList(deptList);
        // 打卡人员
        attendRuleAddDTO.setStaffList(staffList);
        // 白名单
        attendRuleAddDTO.setWhitelist(whitelist);
        // 汇报对象
        attendRuleAddDTO.setReportList(reportList);
        // 打卡地点-位置
        attendRuleAddDTO.setLocationList(locationList);
        // 打卡地点-wifi
        attendRuleAddDTO.setWifiList(wifiList);
        // 打卡时间
        attendRuleAddDTO.setPunchTimeList(punchTimeList);
        // 特殊日期-必须打卡的日期
        attendRuleAddDTO.setNeedPunchDateList(needPunchDateList);
        // 特殊日期-不必打卡的日期
        attendRuleAddDTO.setNoNeedPunchDateList(noNeedPunchDateList);
        // 加班规则不能为空
        attendRuleAddDTO.setOvertimeRule(overtimeRule);
        // 是否同步中国节假日不能为空
//        attendRuleAddDTO.setIsSynchLegalHoliday(isSynchLegalHoliday);
//        // 是否手机提醒
//        attendRuleAddDTO.setIsRemind(isRemind);
//        // 上班前x分钟
//        attendRuleAddDTO.setRemindBefore(remindBefore);
//        // 下班后x分钟
//        attendRuleAddDTO.setRemindAfter(remindAfter);
//        // 员工打卡时必须拍照不能为空
//        attendRuleAddDTO.setIsTakePhoto(isTakePhoto);
//        // 只能拍照
//        attendRuleAddDTO.setIsOnlyPhoto(isOnlyPhoto);
//        // 范围外打卡
//        attendRuleAddDTO.setPunchRange(punchRange);
//        // 是否补卡申请
//        attendRuleAddDTO.setIsMakeUp(isMakeUp);
        // 每月不高于x下次
        attendRuleAddDTO.setMaxMakeUpCounts(maxMakeUpCounts);
        // 生效时间
        attendRuleAddDTO.setTakeEffect(takeEffect);

        return attendRuleAddDTO;
    }

    public AttendPlanVO saveAttendRule() {

        AttendRuleAddDTO attendRuleAddDTO = new AttendRuleAddDTO();

        // 方案名称
        String planName = "工作日考勤规则一";
        // 方案类型 ; 1-固定时间上下班,2-按班次上下班,3-自由上下班
        int planType = 1;
        // 打卡部门
        List<AttendRuleDeptAddDTO> deptList = this.getDeptList();
        // 打卡人员
        List<AttendRuleStaffAddDTO> staffList = this.getStaffList();
        // 白名单
        List<AttendRuleWhitelistAddDTO> whitelist = this.getWhitelist();
        // 汇报对象
        List<AttendRuleReportAddDTO> reportList = this.getReportList();
        // 打卡地点-位置
        List<AttendRuleLocationAddDTO> locationList = this.getLocationList();
        // 打卡地点-wifi
        List<AttendRuleWifiAddDTO> wifiList = this.getWifiList();
        // 打卡时间
        List<AttendRulePunchTimeAddDTO> punchTimeList = this.getPunchTimeList();
        // 特殊日期-必须打卡的日期
        List<NeedPunchDateAddDTO> needPunchDateList = this.getNeedPunchDateList();
        // 特殊日期-不必打卡的日期
        List<NoNeedPunchDateAddDTO> noNeedPunchDateList = this.getNoNeedPunchDateList();
        // 加班规则 1-以加班申请为准,2-以打卡时间为准,3-以加班申请核算打卡记录
        int overtimeRule = 1;
        // 是否同步中国节假日不能为空
        int isSynchLegalHoliday = 0;
        // 是否手机提醒;1-是,0-否
        int isRemind = 1;
        // 上班前x分钟
        int remindBefore = 0;
        // 下班后x分钟
        int remindAfter = 0;
        // 员工打卡时必须拍照
        int isTakePhoto = 0;
        // 只能拍照
        int isOnlyPhoto = 0;
        // 范围外打卡
        int punchRange = 1;
        // 是否补卡申请
        int isMakeUp = 0;
        // 每月不高于x下次
        int maxMakeUpCounts = 0;
        // 生效时间
        int takeEffect = 0;

        // 方案名称
        attendRuleAddDTO.setPlanName(planName);
        // 规则类型不能为空 (1-固定时间上下班,2-按班次上下班,3-自由上下班)
        attendRuleAddDTO.setPlanType(planType);
        // 打卡部门
        attendRuleAddDTO.setDeptList(deptList);
        // 打卡人员
        attendRuleAddDTO.setStaffList(staffList);
        // 白名单
        attendRuleAddDTO.setWhitelist(whitelist);
        // 汇报对象
        attendRuleAddDTO.setReportList(reportList);
        // 打卡地点-位置
        attendRuleAddDTO.setLocationList(locationList);
        // 打卡地点-wifi
        attendRuleAddDTO.setWifiList(wifiList);
        // 打卡时间
        attendRuleAddDTO.setPunchTimeList(punchTimeList);
        // 特殊日期-必须打卡的日期
        attendRuleAddDTO.setNeedPunchDateList(needPunchDateList);
        // 特殊日期-不必打卡的日期
        attendRuleAddDTO.setNoNeedPunchDateList(noNeedPunchDateList);
        // 加班规则不能为空
        attendRuleAddDTO.setOvertimeRule(overtimeRule);
        // 是否同步中国节假日不能为空
//        attendRuleAddDTO.setIsSynchLegalHoliday(isSynchLegalHoliday);
//        // 是否手机提醒
//        attendRuleAddDTO.setIsRemind(isRemind);
//        // 上班前x分钟
//        attendRuleAddDTO.setRemindBefore(remindBefore);
//        // 下班后x分钟
//        attendRuleAddDTO.setRemindAfter(remindAfter);
//        // 员工打卡时必须拍照不能为空
//        attendRuleAddDTO.setIsTakePhoto(isTakePhoto);
//        // 只能拍照
//        attendRuleAddDTO.setIsOnlyPhoto(isOnlyPhoto);
//        // 范围外打卡
//        attendRuleAddDTO.setPunchRange(punchRange);
//        // 是否补卡申请
//        attendRuleAddDTO.setIsMakeUp(isMakeUp);
        // 每月不高于x下次
        attendRuleAddDTO.setMaxMakeUpCounts(maxMakeUpCounts);
        // 生效时间
        attendRuleAddDTO.setTakeEffect(takeEffect);

        return attendRuleService.save(attendRuleAddDTO, buildTokenUser());
    }


    /**
     * 打卡部门
     *
     * @return
     */
    public List<AttendRuleDeptAddDTO> getDeptList() {

        List<AttendRuleDeptAddDTO> deptList = new ArrayList<>();

        // 部门一
        AttendRuleDeptAddDTO dept1 = new AttendRuleDeptAddDTO();
        dept1.setDeptId("42DA81D823034735AE8F0C7E4A2ECE02");
        dept1.setDeptName("部门一");
        deptList.add(dept1);

        // 部门二
        AttendRuleDeptAddDTO dept2 = new AttendRuleDeptAddDTO();
        dept1.setDeptId("4C691F73374343AA9337082F22138038");
        dept1.setDeptName("部门二");
        deptList.add(dept2);

        return deptList;
    }

    /**
     * 随机获取部门
     *
     * @param depList
     * @return
     */
    public List<AttendRuleDeptAddDTO> getDeptList(List<DepInfoVO> depList) {

        List<AttendRuleDeptAddDTO> deptList = new ArrayList<>();

        int max=depList.size() - 1,min=1;

        for (int i = 0; i < 5; i++) {

            int ran2 = (int) (Math.random()*(max-min)+min);
            DepInfoVO depInfoVO = depList.get(ran2);

            if (depInfoVO != null) {
                AttendRuleDeptAddDTO dept = new AttendRuleDeptAddDTO();
                dept.setDeptId(depInfoVO.getId());
                dept.setDeptName(depInfoVO.getName());
                deptList.add(dept);
            }

        }
        return deptList;
    }


    public List<AttendRuleStaffAddDTO> getStaffList(List<EmpInfoVO> empInfoList, List<DepInfoVO> depList) {

        List<AttendRuleStaffAddDTO> staffList = new ArrayList<>();

        int max = empInfoList.size() - 1,min = 1;

        for (int i = 0; i < 5; i++) {

            int ran2 = (int) (Math.random()*(max-min)+min);

            EmpInfoVO empInfoVO = empInfoList.get(ran2);

            int ran3 = (int) (Math.random()*(depList.size() - 1) + 1);

            DepInfoVO depInfoVO = depList.get(ran3);

            AttendRuleStaffAddDTO staff1 = new AttendRuleStaffAddDTO();
            staff1.setEmpInfoId(empInfoVO.getId());
            staff1.setEmpInfoName(empInfoVO.getName());
            staff1.setDepInfoName(depInfoVO.getName());
            staff1.setDepInfoId(depInfoVO.getId());
            staffList.add(staff1);
        }

        return staffList;
    }

    /**
     * 打卡人员
     *
     * @return
     */
    public List<AttendRuleStaffAddDTO> getStaffList() {

        List<AttendRuleStaffAddDTO> staffList = new ArrayList<>();

        AttendRuleStaffAddDTO staff1 = new AttendRuleStaffAddDTO();
        staff1.setEmpInfoId("1940931DC4564ECDA5373D212429452A");
        staff1.setEmpInfoName("员工一");
        staffList.add(staff1);

        AttendRuleStaffAddDTO staff2 = new AttendRuleStaffAddDTO();
        staff2.setEmpInfoId("469C9C04F8DE4BDC83A0873FD11069EA");
        staff2.setEmpInfoName("员工二");
        staffList.add(staff2);

        AttendRuleStaffAddDTO staff3 = new AttendRuleStaffAddDTO();
        staff3.setEmpInfoId("5141EE3EDC554EB28638474343A982E9");
        staff3.setEmpInfoName("员工三");
        staffList.add(staff3);

        return staffList;
    }

    public List<AttendRuleWhitelistAddDTO> getWhitelist(List<EmpInfoVO> empInfoList, List<DepInfoVO> depList) {

        List<AttendRuleWhitelistAddDTO> whitelist = new ArrayList<>();

        int max = empInfoList.size() - 1,min = 1;

        for (int i = 0; i < 5; i++) {

            int ran2 = (int) (Math.random() * (max - min) + min);
            EmpInfoVO empInfoVO = empInfoList.get(ran2);

            int ran3 = (int) (Math.random()*(depList.size() - 1) + 1);
            DepInfoVO depInfoVO = depList.get(ran3);

            AttendRuleWhitelistAddDTO white1 = new AttendRuleWhitelistAddDTO();
            white1.setEmpInfoId(empInfoVO.getId());
            white1.setEmpInfoName(empInfoVO.getName());
            white1.setDepInfoId(depInfoVO.getId());
            white1.setDepInfoName(depInfoVO.getName());

            whitelist.add(white1);
        }

        return whitelist;
    }

    /**
     * 白名单
     *
     * @return
     */
    public List<AttendRuleWhitelistAddDTO> getWhitelist() {

        List<AttendRuleWhitelistAddDTO> whitelist = new ArrayList<>();

        AttendRuleWhitelistAddDTO white1 = new AttendRuleWhitelistAddDTO();
        white1.setEmpInfoId("5141EE3EDC554EB28638474343A982E9");
        white1.setEmpInfoName("员工一");
        whitelist.add(white1);

        AttendRuleWhitelistAddDTO white2 = new AttendRuleWhitelistAddDTO();
        white2.setEmpInfoId("469C9C04F8DE4BDC83A0873FD11069EA");
        white2.setEmpInfoName("员工2");
        whitelist.add(white2);

        return whitelist;
    }

    public List<AttendRuleReportAddDTO> getReportList(List<EmpInfoVO> empInfoList, List<DepInfoVO> depList) {

        List<AttendRuleReportAddDTO> reportList = new ArrayList<>();

        int max = empInfoList.size() - 1,min = 1;

        for (int i = 0; i < 5; i++) {

            int ran2 = (int) (Math.random() * (max - min) + min);
            EmpInfoVO empInfoVO = empInfoList.get(ran2);

            int ran3 = (int) (Math.random()*(depList.size() - 1) + 1);
            DepInfoVO depInfoVO = depList.get(ran3);

            AttendRuleReportAddDTO report1 = new AttendRuleReportAddDTO();
            report1.setEmpInfoId(empInfoVO.getId());
            report1.setEmpInfoName(empInfoVO.getName());
            report1.setDepInfoId(depInfoVO.getId());
            report1.setDepInfoName(depInfoVO.getName());
            reportList.add(report1);
        }

        return reportList;
    }

    /**
     * 汇报对象
     *
     * @return
     */
    public List<AttendRuleReportAddDTO> getReportList() {

        List<AttendRuleReportAddDTO> reportList = new ArrayList<>();

        AttendRuleReportAddDTO report1 = new AttendRuleReportAddDTO();
        report1.setEmpInfoId("71AB7AC5726A4416BE20016A65AC4257");
        report1.setEmpInfoName("小米");
        reportList.add(report1);

        AttendRuleReportAddDTO report2 = new AttendRuleReportAddDTO();
        report2.setEmpInfoId("726A64D987B34385BA08564A707F4E2C");
        report2.setEmpInfoName("小明");
        reportList.add(report2);

        return reportList;
    }

    /**
     * 打卡地点-位置
     *
     * @return
     */
    public List<AttendRuleLocationAddDTO> getLocationList() {

        List<AttendRuleLocationAddDTO> locationList = new ArrayList<>();

        AttendRuleLocationAddDTO local1 = new AttendRuleLocationAddDTO();
        local1.setPunchLongitude("116.644009");
        local1.setPunchLatitude("40.010055");
        local1.setPositionName("中央人民广场");
        local1.setDistance(1);
        locationList.add(local1);

        AttendRuleLocationAddDTO local2 = new AttendRuleLocationAddDTO();
        local1.setPunchLongitude("116.644009");
        local1.setPunchLatitude("40.010055");
        local2.setPositionName("中央人民广场");
        local2.setDistance(2);
        locationList.add(local2);

        AttendRuleLocationAddDTO local3 = new AttendRuleLocationAddDTO();
        local1.setPunchLongitude("116.644009");
        local1.setPunchLatitude("40.010055");
        local3.setPositionName("中央人民广场");
        local3.setDistance(3);
        locationList.add(local3);

        return locationList;
    }

    /**
     *  打卡地点-wifi
     *
     * @return
     */
    public List<AttendRuleWifiAddDTO> getWifiList() {

        List<AttendRuleWifiAddDTO> wifiList = new ArrayList<>();

        AttendRuleWifiAddDTO wifi1 = new AttendRuleWifiAddDTO();
        wifi1.setName("wifi1");
        wifi1.setMacAddr("xcxcxcxcxc");
        wifiList.add(wifi1);

        AttendRuleWifiAddDTO wifi2 = new AttendRuleWifiAddDTO();
        wifi2.setName("wifi2");
        wifi2.setMacAddr("xcxcxcxc");
        wifiList.add(wifi2);

        return wifiList;
    }


    public static void main(String[] args) {

        int max = 7,min = 1;
        int ran2 = (int) (Math.random() * (max - min) + min);

        System.out.println(ran2);

    }

    public List<AttendRulePunchTimeAddDTO> getPunchTimeListRandomFree() {

        List<AttendRulePunchTimeAddDTO> punchTimeList = new ArrayList<>();

        for (int i = 0; i < 3; i++) {
            AttendRulePunchTimeAddDTO time = new AttendRulePunchTimeAddDTO();

            List<String> weekList = new ArrayList<>();

            int max = 7,min = 1;
            int ran = (int) (Math.random() * (max - min) + min);

            for (int j = 0; j < ran; j++) {

                int ran2 = (int) (Math.random() * (max - min) + min);
                if (ran2 == 1) {
                    weekList.add("星期一");
                }
                if (ran2 == 2) {
                    weekList.add("星期二");
                }
                if (ran2 == 3) {
                    weekList.add("星期三");
                }
                if (ran2 == 4) {
                    weekList.add("星期四");
                }
                if (ran2 == 5) {
                    weekList.add("星期五");
                }
                if (ran2 == 6) {
                    weekList.add("星期六");
                }
                if (ran2 == 7) {
                    weekList.add("星期日");
                }
            }

            time.setWorkWeekList(weekList);

            punchTimeList.add(time);
        }

        return punchTimeList;
    }

    public List<AttendRulePunchTimeAddDTO> getPunchTimeListRandom() {

        List<AttendRulePunchTimeAddDTO> punchTimeList = new ArrayList<>();

        for (int i = 0; i < 3; i++) {
            AttendRulePunchTimeAddDTO time = new AttendRulePunchTimeAddDTO();

            List<String> weekList = new ArrayList<>();

            int max = 7,min = 1;
            int ran = (int) (Math.random() * (max - min) + min);

            for (int j = 0; j < ran; j++) {

                int ran2 = (int) (Math.random() * (max - min) + min);
                if (ran2 == 1) {
                    weekList.add("星期一");
                }
                if (ran2 == 2) {
                    weekList.add("星期二");
                }
                if (ran2 == 3) {
                    weekList.add("星期三");
                }
                if (ran2 == 4) {
                    weekList.add("星期四");
                }
                if (ran2 == 5) {
                    weekList.add("星期五");
                }
                if (ran2 == 6) {
                    weekList.add("星期六");
                }
                if (ran2 == 7) {
                    weekList.add("星期日");
                }
            }

            List<AttendPeriodDTO> periodList = attendPeriodTestHelper.getAttendPeriod();

            time.setWorkWeekList(weekList);
            time.setPeriodList(periodList);

            time.setIsAllowedLateEarly(SafeKit.getInteger(getRandomValue("tinyint",0)));
            time.setLateMinute(SafeKit.getInteger(getRandomValue("int",0)));
            time.setEarlyMinute(SafeKit.getInteger(getRandomValue("int",0)));

            time.setIsAllowLateLate(SafeKit.getInteger(getRandomValue("tinyint",0)));
            time.setOffWorkLateMinute(SafeKit.getInteger(getRandomValue("int",0)));
            time.setOnWorkLateMinute(SafeKit.getInteger(getRandomValue("int",0)));

            time.setEarliestPunchTime(SafeKit.getInteger(getRandomValue("int",0)) + "");
            time.setLatestPunchTime(SafeKit.getInteger(getRandomValue("int",0)) + ""); // 最晚下班打卡时间(分钟)
            time.setAfterWorkNeedPunch(SafeKit.getInteger(getRandomValue("tinyint",0))); // 下班是否需要打卡;1-是,0-否

            punchTimeList.add(time);
        }

        return punchTimeList;
    }



    /**
     * 打卡时间
     *
     * @return
     */
    public List<AttendRulePunchTimeAddDTO> getPunchTimeList() {

        List<AttendRulePunchTimeAddDTO> punchTimeList = new ArrayList<>();

        AttendRulePunchTimeAddDTO time1 = new AttendRulePunchTimeAddDTO();
        List<String> weekList = new ArrayList<>();
        weekList.add("星期一");
        weekList.add("星期二");
        time1.setWorkWeekList(weekList); // 工作周;星期一,星期二

        List<AttendPeriodDTO> periodList = new ArrayList<>();

        AttendPeriodDTO attendPeriod1 = new AttendPeriodDTO();
        attendPeriod1.setStartPeriod("08:00");
        attendPeriod1.setEndPeriod("09:00");
        attendPeriod1.setType(1);
        periodList.add(attendPeriod1);

        AttendPeriodDTO attendPeriod2 = new AttendPeriodDTO();
        attendPeriod2.setStartPeriod("08:00");
        attendPeriod2.setEndPeriod("09:00");
        attendPeriod2.setType(2);
        periodList.add(attendPeriod2);

        time1.setPeriodList(periodList); // 打卡时段;80:00-12:00,13:00-18:00

        time1.setIsAllowedLateEarly(1); // 允许迟到早退；1-允许,0-不允许
        time1.setLateMinute(5); //上班允许迟到(分钟)
        time1.setEarlyMinute(5); // 下班允许早退(分钟)

        time1.setIsAllowLateLate(1); // 允许晚走晚到;1-允许,0-不允许
        time1.setOffWorkLateMinute(5); // 下班晚走(分钟)
        time1.setOnWorkLateMinute(5); // 上班晚到(分钟)

        time1.setEarliestPunchTime("80"); // 最早上班打卡时间
        time1.setLatestPunchTime("90"); // 最晚下班打卡时间(分钟)
        time1.setAfterWorkNeedPunch(1); // 下班是否需要打卡;1-是,0-否

        punchTimeList.add(time1);

        return punchTimeList;
    }

    public List<NeedPunchDateAddDTO> getNeedPunchDateList() {

        List<NeedPunchDateAddDTO> needPunchDateList = new ArrayList<>();

        for (int i = 0; i < 3; i++) {

            NeedPunchDateAddDTO needPunchDate1 = new NeedPunchDateAddDTO();
            needPunchDate1.setDaily(new SimpleDateFormat("yyyy-MM-dd").format(randomDate("2020-01-01","2020-02-02")));
            needPunchDate1.setPeriodList(attendPeriodTestHelper.getAttendPeriod());
            needPunchDate1.setReason("xxxx");
            needPunchDateList.add(needPunchDate1);

        }
        return needPunchDateList;
    }

    private static Date randomDate(String beginDate, String endDate){
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Date start = format.parse(beginDate);
            Date end = format.parse(endDate);

            if(start.getTime() >= end.getTime()){
                return null;
            }
            long date = random(start.getTime(),end.getTime());
            return new Date(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private static long random(long begin,long end){
        long rtn = begin + (long)(Math.random() * (end - begin));
        if(rtn == begin || rtn == end){
            return random(begin,end);
        }
        return rtn;
    }

    /**
     * 特殊日期-不必打卡的日期
     *
     * @return
     */
    public List<NoNeedPunchDateAddDTO> getNoNeedPunchDateList() {

        List<NoNeedPunchDateAddDTO> noNeedPunchDateList = new ArrayList<>();

        NoNeedPunchDateAddDTO noNeedPunch1 = new NoNeedPunchDateAddDTO();
        noNeedPunch1.setDaily(new SimpleDateFormat("yyyy-MM-dd").format(randomDate("2020-01-01","2020-02-02")));
        noNeedPunch1.setReason("xxxxx");

        NoNeedPunchDateAddDTO noNeedPunch2 = new NoNeedPunchDateAddDTO();
        noNeedPunch2.setDaily(new SimpleDateFormat("yyyy-MM-dd").format(randomDate("2020-01-01","2020-02-02")));
        noNeedPunch2.setReason("xxxxx");

        noNeedPunchDateList.add(noNeedPunch1);
        noNeedPunchDateList.add(noNeedPunch2);

        return noNeedPunchDateList;
    }

}
